package com.njtoyo.netrides.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.experimental.Accessors;

import javax.persistence.*;
import java.math.BigDecimal;
import java.util.Date;
import java.util.Set;

/**
 * Created by astropete on 2017/8/16.
 */
@Entity
@Table(name = "driver")
@Data
@Accessors(chain = true)
@EqualsAndHashCode(of = {"id"})
public class Driver {

    @Id
    @Column(name = "id", nullable = false)
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    private Long id;

    private String name;

    private String mobileNumber;

    private String password;

    private String avatarUrl;

    @Transient
    @JsonIgnore
    private Long userId;

    @ManyToOne(fetch = FetchType.EAGER)
    @JoinColumn(name = "taxi_id")
    private Taxi taxi;

    private Integer locateCityId;

    /**
     * 司机运营区ID
     */
    private Long driverRegionId;

    /**
     * 运营区ID
     */
    private Long cantonId;

    @Column(name = "is_active", nullable = false, columnDefinition = "TINYINT(1)")
    private Boolean isActive;

    @Column(name = "in_service", nullable = false, columnDefinition = "TINYINT(1)")
    private Boolean inService;

    @Column(name = "is_substitute", nullable = false, columnDefinition = "TINYINT(1)")
    private Boolean isSubstitute;

    @JsonIgnore
    private Date createdAt;

    private String deviceInfo;

    /**
     * 司机分数
     */
    @Transient
    private Integer score;

    /**
     * 司机分数（带有小数）
     */
    private Double markScore;

    /**
     * 听单类型
     */
    private Znum.AcceptCallCtg acceptCallCtg;

    /**
     * 实时单听单范围
     */
    private Double realtimeCallDistanceRange;

    /**
     * 是否自动抢单（仅实时单可用）
     */
    private Boolean isAutomatic;

    /**
     * 自动抢单范围
     */
    private Double automaticOrderRange;

    @Transient
    private String distanceRange;

    @OneToMany(mappedBy = "driver", cascade = CascadeType.ALL, fetch = FetchType.LAZY)
    @JsonIgnore
    @Transient
    private Set<Ride> rides;

    @Transient
    private BigDecimal totalRideEarning;

    @Transient
    private BigDecimal totalRideOnlineEarning;

    @Transient
    private BigDecimal rewardEarning;

    @Transient
    private BigDecimal forceCancelCompensate;

    @Transient
    private BigDecimal withdrawAmount;

    @Transient
    private Integer rideCount;

    @Transient
    private Integer mark;

    @Transient
    private Integer recommendCount;

    @Transient
    private BigDecimal streetRideEarning;

    /**
     * 分销会员费
     */
    @Transient
    private BigDecimal memberFee;

    /**
     * 司机接单量
     */
    @Transient
    private Integer driverOrderCount;

    /**
     * 今日订单量(打车、街边招车、用户取消、推广都包括)
     */
    @Transient
    private Integer todayOrderCount;

    /**
     * 今日线上收入(推荐奖励 + 接单红包奖励 + 司机接单收入（实际所得）+ 街边扫码付款+乘客空驶费)
     */
    @Transient
    private BigDecimal todayOrderAmount;

    /**
     * 今日现金收入
     */
    @Transient
    private BigDecimal todayCashAmount;

    /**
     * 今日收入（今日现金收入 + 今日线上收入）
     */
    @Transient
    private BigDecimal todayAmount;

    /**
     * 今日奖励收入
     */
    @Transient
    private BigDecimal todayRewardAmount;

    /**
     * 司机获得的返利
     */
    @Transient
    private BigDecimal driverRebate;

    private String refreshToken;

    @Transient
    private Boolean signInTimeValid;

    private String entityName;

    @Column(name = "is_leave", nullable = false, columnDefinition = "TINYINT(1)")
    private Boolean isLeave;

    private Date leaveTime;

    /**
     * 司机缓存中的账户余额
     */
    @Transient
    private BigDecimal accountAmount;

    /**
     * 司机未开启红包个数
     */
    @Transient
    private Integer notOpenRedPacket;

}